﻿using System;
using ltModel;

public partial class ltMan_singles_SingleOperate : AdminBaseUserControl
{
    ltModel.BLL.article_content_only aco = new ltModel.BLL.article_content_only();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = Request.QueryString["id"];
            if (Str.IsInt(id))
            {
                ltModel.Model.article_content_only acom = aco.GetModel(int.Parse(id));
                stitle.Text = acom.title;
                stype.Text = acom.classtype;
                News_content.Value = acom.content;
            }
        }
    }
    protected void RadSave_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];
        bool inEdit = Str.IsInt(id);
        ltModel.Model.article_content_only acom = null;
        if (inEdit)
            acom = aco.GetModel(int.Parse(id));
        else
            acom = new ltModel.Model.article_content_only();

        acom.title = DataProtector.ToSBC(stitle.Text);
        acom.classtype = DataProtector.ToSBC(stype.Text);
        acom.content = News_content.Value.Replace("'", "''");
        if (string.IsNullOrEmpty(acom.title) ||
            string.IsNullOrEmpty(acom.content))
        {
            infoPanel.AddErrorInfo("标题、内容必须填写！");
            OperateLog.AddFailedLog(CurrentUser.user_id, Request.UserHostAddress, "单篇管理->标题、内容必须填写");
            return;
        }

        if (inEdit)
        {
            OperateLog.AddSuccessLog(CurrentUser.user_id, Request.UserHostAddress, "单篇管理-修改>" + acom.title);
            aco.Update(acom);
        }
        else
        {
            acom.addtime = DateTime.Now.ToString();
            OperateLog.AddSuccessLog(CurrentUser.user_id, Request.UserHostAddress, "单篇管理-添加>" + acom.title);
            aco.Add(acom);
        }
        infoPanel.AddSuccessInfo(inEdit ? "修改成功" : "添加成功");
        AddScriptM("setTimeout(function(){if (top.treeWithTab){top.treeWithTab.deleteTabByUrl('" + Request.RawUrl + "');}else{location='singleList.aspx';}}, 300);");
    }
}